﻿using System;
using System.Collections.Generic;

using System.Windows;
using System.Windows.Controls;

using System.Windows.Input;
using System.Windows.Media.Animation;

using System.Threading;

namespace EagleJournal
{
	public partial class ScreenMain : UserControl
	{
        public static readonly  RoutedEvent
            InvokeNotificationButtonClickedEvent    = EventManager.RegisterRoutedEvent("InvokeNotificationButtonClicked", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ScreenMain));
        public event            RoutedEventHandler
            InvokeNotificationButtonClicked
        {
            add     { this.AddHandler(InvokeNotificationButtonClickedEvent, value); }
            remove  { this.RemoveHandler(InvokeNotificationButtonClickedEvent, value); }
        }

        public static readonly  RoutedEvent
            InvokeButtonClientClickedEvent          = EventManager.RegisterRoutedEvent("InvokeButtonClientClick", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ScreenMain));
        public event            RoutedEventHandler
            InvokeButtonClientClicked
        {
            add     { this.AddHandler(InvokeButtonClientClickedEvent, value); }
            remove  { this.RemoveHandler(InvokeButtonClientClickedEvent, value); }
        }

        public static readonly  RoutedEvent
            InvokeButtonOrdersClickedEvent          = EventManager.RegisterRoutedEvent("InvokeButtonOrdersClick", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ScreenMain));
        public event            RoutedEventHandler
            InvokeButtonOrdersClicked
        {
            add { this.AddHandler(InvokeButtonOrdersClickedEvent, value); }
            remove { this.RemoveHandler(InvokeButtonOrdersClickedEvent, value); }
        }

        public static readonly  RoutedEvent
            InvokeLogoutConfirmedEvent              = EventManager.RegisterRoutedEvent("InvokeLogoutConfirmed", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ScreenMain));
        public event            RoutedEventHandler
            InvokeLogoutConfirmed
        {
            add     { this.AddHandler(InvokeLogoutConfirmedEvent, value); }
            remove  { this.RemoveHandler(InvokeLogoutConfirmedEvent, value); }
        }

        public static readonly  RoutedEvent
            InvokeHelpButtonClickedEvent            = EventManager.RegisterRoutedEvent("InvokeHelpButtonClicked", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(ScreenMain));
        public event RoutedEventHandler
            InvokeHelpButtonClicked
        {
            add     { this.AddHandler(InvokeHelpButtonClickedEvent, value); }
            remove  { this.RemoveHandler(InvokeHelpButtonClickedEvent, value); }
        }

        Storyboard showLogout;
        Storyboard hideLogout;

		public                  ScreenMain              ()
		{
			this.InitializeComponent();
		}

        public override void    OnApplyTemplate         ()
        {
            base.OnApplyTemplate();

            showLogout = (Storyboard)this.FindResource("ShowLogout");
            hideLogout = (Storyboard)this.FindResource("HideLogout");
            hideLogout.Completed += new EventHandler((o, sbe) =>
            {
                this.RootGrid.Children.Remove(this.Dimmer);
                this.RootGrid.Children.Remove(this.LogoutGrid);
            });

            showLogout.Freeze();
            hideLogout.Freeze();
        }

        private         void    ButtonNotif_Click       (object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(InvokeNotificationButtonClickedEvent));
        }

        private         void    ButtonClient_Click      (object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(InvokeButtonClientClickedEvent));
        }
        private         void    ButtonOrder_Click       (object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(InvokeButtonOrdersClickedEvent));
        }

        private         void    ButtonLogout_Click      (object sender, RoutedEventArgs e)
        {
            if (!this.RootGrid.Children.Contains(this.Dimmer))
                this.RootGrid.Children.Add(this.Dimmer);

            if (!this.RootGrid.Children.Contains(this.LogoutGrid))
                this.RootGrid.Children.Add(this.LogoutGrid);

            this.BeginStoryboard(showLogout);
        }
        private         void    ButtonLogoutYes_Click   (object sender, RoutedEventArgs e)
        {
            this.BeginStoryboard(hideLogout);

            this.RaiseEvent(new RoutedEventArgs(InvokeLogoutConfirmedEvent));
        }
        private         void    ButtonLogoutNo_Click    (object sender, RoutedEventArgs e)
        {
            this.BeginStoryboard(hideLogout);
        }

        private         void    ButtonHelp_Click        (object sender, RoutedEventArgs e)
        {
            this.RaiseEvent(new RoutedEventArgs(InvokeHelpButtonClickedEvent));
        }
	}
}